#include "t1_crypto.h"
#include "syscfg.h"
#include "iodev.h"
#include "ioctl.h"
#include <string.h>
#include "init.h"
#include "clk.h"


static int rng_init(iodev_t *dev)
{
        SYSCFG->RNG_CTL = RNG_EN;

        return 0;
}
static ssize_t rng_read(iodev_t *dev, void *buffer, size_t size)
{
        uint8_t * pbuf = (uint8_t *)buffer;
        uint8_t temp;
        int i, j;
        
        for (i = 0; i < size; i ++) {
                temp = 0;
                for (j = 0; j < 8; j ++) {
                        temp |= ((SYSCFG->RNG_VAL & 0x01) << j);
                }
                *(pbuf++) = temp;
        }
        
        return size;
}


static const iodev_t T1_rng __iodev_entry = {
        .name = "rng",
        .priv = NULL,
        .init = rng_init,
        .read = rng_read,
        .write = NULL,
        .ioctl = NULL,
        .poll = NULL,
};
